const {responsSuccess,responsError} = require('request-common')  // 引入公共模块
const OpenAI = require("openai");

const client = new OpenAI({
    apiKey: "sk-A6nhxwIYFbPoK8PCoO1VYLYw7odcR0KE6f0NBFkQtoiHt2Kl",    
    baseURL: "https://api.moonshot.cn/v1",
});

module.exports = {
	_before: function () { // 通用预处理器
		
	},
	chatContent:[],
	chat:async (history)=>{
		try{
			const completion = await client.chat.completions.create({
			        model: "moonshot-v1-8k",         
			        messages: history,
			}); 
			console.log(completion,123123123)
			return responsSuccess(completion.choices[0].message.content) 
		}catch(err){
			return responsError(500,'系统错误',err)
		}
	}
}
